<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>addAddress</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<style type="text/css">
			p {
				margin: 0;
				padding: 0;
			}

			body,
			input,
			select,
			textarea {
				font-size: 14px;
			}

			.mui-title {
				text-align: left;
			}

			.mui-input-row {
				clear: none;
			}

			.mui-input-row label {
				width: 25%;
			}

			.mui-input-row label~input,
			.mui-input-row label~select,
			.mui-input-row label~textarea {
				width: 75%;
			}

			.mui-input-row .mui-input-row label {
				width: 100%;
			}

			.mui-checkbox.mui-left input[type=checkbox],
			.mui-radio.mui-left input[type=radio] {
				left: 0;
			}

			.mui-checkbox.mui-left label,
			.mui-radio.mui-left label {
				padding-left: 40px;
				padding-right: 33px;
			}

			.mui-content p {
				height: 40px;
				line-height: 40px;
				padding-left: 15px;
				font-size: 14px;
				background-color: #EFEFF4;
			}

			.pr0 label {
				padding: 11px 0 11px 15px;
				width: 36%;
			}

			.pr0.mui-input-row label~input,
			.mui-input-row label~select,
			.mui-input-row label~textarea {
				width: 64%;
			}
		</style>
	</head>

	<body>
		<!--<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">新增收货地址</h1>
		</header>-->
		<div class="mui-content" id="formContent">
			<!--编辑-->
			<form class="mui-input-group" id="commonForm" v-if="status">
				<input type="hidden" name="addressId" id="addressId" :value="typeId" />
				<p>联系人</p>
				<div class="mui-input-row">
					<label>姓名:</label>
					<input type="text" class="mui-input-clear" name="name" :value="editData.name" placeholder="请填写收货人的姓名">
				</div>
				<div class="mui-input-row">
					<label></label>
					<div class="mui-input-row mui-radio mui-pull-left mui-left">
						<label>先生</label>
						<input type="radio" name="gender" value="0" checked="">
					</div>
					<div class="mui-input-row mui-radio mui-pull-left mui-left">
						<label>女士</label>
						<input type="radio" name="gender" value="1">
					</div>
				</div>
				<div class="mui-input-row">
					<label>手机:</label>
					<input type="number" class="mui-input-phone" name="phonenumber" :value="editData.phonenumber" placeholder="请填写收货手机号码">
				</div>
				<p>收货地址</p>
				<div class="mui-input-row pr0">
					<label>小区/大厦/学校:</label>
					<input type="text" class="mui-input-phone" name="building" :value="editData.building" placeholder=" 点击选择">
				</div>
				<div class="mui-input-row pr0">
					<label>楼号-门牌号:</label>
					<input type="text" class="mui-input-phone" name="doorplate" :value="editData.doorplate" placeholder="例:16号楼427室">
				</div>
				<div class="mui-button-row">
					<button type="button" @click="submitFun('/address/update')" class="mui-btn mui-btn-primary">保存</button>
				</div>
			</form>
			<!--新增-->
			<form class="mui-input-group" id="commonForm" v-if="!status">
				<p>联系人</p>
				<div class="mui-input-row">
					<label>姓名:</label>
					<input type="text" class="mui-input-clear" name="name" placeholder="请填写收货人的姓名">
				</div>
				<div class="mui-input-row">
					<label></label>
					<div class="mui-input-row mui-radio mui-pull-left mui-left">
						<label>先生</label>
						<input type="radio" name="gender" value="0" checked="">
					</div>
					<div class="mui-input-row mui-radio mui-pull-left mui-left">
						<label>女士</label>
						<input type="radio" name="gender" value="1">
					</div>
				</div>
				<div class="mui-input-row">
					<label>手机:</label>
					<input type="number" class="mui-input-phone" name="phonenumber" placeholder="请填写收货手机号码">
				</div>
				<p>收货地址</p>
				<div class="mui-input-row pr0">
					<label>小区/大厦/学校:</label>
					<input type="text" class="mui-input-phone" name="building" placeholder=" 点击选择">
				</div>
				<div class="mui-input-row pr0">
					<label>楼号-门牌号:</label>
					<input type="text" class="mui-input-phone" name="doorplate" placeholder="例:16号楼427室">
				</div>
				<div class="mui-button-row">
					<button type="button" @click="submitFun('/address/save')" class="mui-btn mui-btn-primary">保存</button>
				</div>
			</form>
		</div>
	</body>
	<script src="js/jquery-1.8.3.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/mui.min.js"></script>
	<script src="js/server.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		var vm = new Vue({
			el: "#formContent",
			data: {
				editData: {},
				status: false,
				typeId: ''
			},
			mounted: function() {
				this.init()
			},
			methods: {
				init: function() {
					//mui.init();
					mui.plusReady(function() {
						var self = plus.webview.currentWebview(); //获取当前窗体对象
						vm.typeId = self.rid; //接受上一页面传过来的值；
						console.log('接收到类型ID值:' + vm.typeId)
						// 判断状态类型  编辑/新增
						if(vm.typeId != null) { //  编辑   ps: null -> 新增
							vm.status = true;
							vm.getData('/address/getByAddressId', 'post', vm.typeId); // 拉去对应ID的数据
						}
					});

				},
				getData: function(path, subtype, addressId) {
					mui.ajax(server + path, {
						dataType: 'json',
						type: subtype,
						data: {
							addressId: addressId
						},
						success: function(res) {
							console.log(res)
							vm.editData = res;
						},
						error: function(type) {
							console.log(type)
						}
					})
				},
				submitFun: function(savePath) {
					mui.ajax(server + savePath, {
						dataType: 'json',
						type: 'post',
						data: $('#commonForm').serialize(),
						success: function(res) {
							console.log(res);
							mui.plusReady(function() {
								var current = plus.webview.currentWebview();
								var address = plus.webview.getWebviewById('address.html'); //查找指定标识的窗口  父页面
								mui.fire(address, "pullRefresh"); //触发首页的 pageflowrefresh 方法
								// 关闭页面写在自定义函数下面   可以解决  关闭login后 → 显示的是用户信息页面 → 显示的是首页
								plus.webview.close(current, 'pop-out');
							})
						},
						error: function(type) {
							console.log(type)
						}
					})
				}
			}
		})
	</script>

</html>